package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.Goods;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.bo.GoodsAllinone;
import com.cskaoyan.model.vo.*;
import com.cskaoyan.model.vo.GoodsDataVO;
import com.cskaoyan.model.vo.GoodsRespVO;
import com.cskaoyan.service.GoodsService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: mall38
 * @description:
 * @author: Wang
 * @create: 2022-05-05 19:39
 **/

@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    /*
     * description 获取商品列表
     * @author Wangtianhao
     * @date 2022-05-09 19:58
     */
    @RequiresPermissions("admin:goods:list")
    @GetMapping("list/**")
    public GoodsRespVO goodsList(String name, Integer goodsId,String goodsSn, BaseParamBO param){
        GoodsDataVO goodsDataVO = goodsService.query(name,goodsId,goodsSn,param);
        return GoodsRespVO.ok(goodsDataVO);
    }

    /*
     * description 获取品牌和类目信息
     * @author Wangtianhao
     * @date 2022-05-09 20:00
     */
    @RequiresPermissions("admin:goods:catAndBrand")
    @GetMapping("catAndBrand")
    public BaseRespVO<CatAndBrandDataVO> catAndBrandList(){
        CatAndBrandDataVO catAndBrandDataVO = goodsService.queryCatAndBrand();
        return BaseRespVO.ok(catAndBrandDataVO);
    }

    /*
     * description 删除商品
     * @author Wangtianhao
     * @date 2022-05-09 20:00
     */
    @RequiresPermissions("admin:goods:delete")
    @PostMapping("delete/**")
    public GoodsRespVO goodsDelete(@RequestBody Goods goods){
      Integer id = goods.getId();
      goodsService.deleteGoodsById(id);
      return GoodsRespVO.ok();
    }

    /*
     * description 新增商品
     * @author Wangtianhao
     * @date 2022-05-08 22:09
     */
    @RequiresPermissions("admin:goods:create")
    @PostMapping("create")
    public GoodsRespVO goodsCreate(@RequestBody GoodsAllinone goodsAllinone){
        goodsService.createGoodsByGoods(goodsAllinone);
        return GoodsRespVO.ok();
    }

    /*
     * description 获取商品信息
     * @author Wangtianhao
     * @date 2022-05-08 22:08
     */
    @RequiresPermissions("admin:goods:detail")
    @GetMapping("detail")
    public GoodsRespVO goodsDetail(Integer id){
        GoodsDetailVO goodsDetailVO = goodsService.getGoodsDetail(id);
        return GoodsRespVO.ok(goodsDetailVO);
    }

    /*
     * description 更新商品
     * @author Wangtianhao
     * @date 2022-05-09 20:01
     */
    @RequiresPermissions("admin:goods:update")
    @PostMapping("update")
    public GoodsRespVO goodsUpdate(@RequestBody GoodsAllinone goodsAllinone){
        goodsService.updateGoodsByGoods(goodsAllinone);
        return GoodsRespVO.ok();
    }
}
